package com.ganzalang.gmall.designpatterns.composite2;

import java.util.ArrayList;

/**
 * @description: 树枝构件
 * @author: Ganzalang
 * @Date 2022/4/11 17:37
 */
public class Composite extends Component{
    /**
     * 构件容器
     */
    private ArrayList componentArrayList = new ArrayList();

    /**
     * 增加一个叶子构件或树枝构件
     *
     * @param component
     */
    public void add(Component component){
        this.componentArrayList.add(component);
    }

    /**
     * 删除一个叶子构件或树枝构件
     *
     * @param component
     */
    public void remove(Component component){
        this.componentArrayList.remove(component);
    }

    /**
     * 获得分支下的所有叶子构件和树枝构件
     *
     * @return
     */
    public ArrayList getChildren(){
        return this.componentArrayList;
    }
}
